package com.sgcc.nfc.lock.data.remote.dto.lock

import com.google.gson.annotations.SerializedName
import com.sgcc.nfc.lock.domain.model.Lock
import com.sgcc.nfc.lock.domain.model.LockStatus
import com.sgcc.nfc.lock.domain.model.LockType

data class LockDto(
    @SerializedName("lockId") val lockId: Long?,
    @SerializedName("lockName") val lockName: String?,
    @SerializedName("lockNfcId") val lockNfcId: String?,
    @SerializedName("lockType") val lockType: Int?,
    @SerializedName("lockStatus") val lockStatus: Int?,
    @SerializedName("batteryLevel") val batteryLevel: Int?,
    @SerializedName("lastHeartbeat") val lastHeartbeat: String?,
    @SerializedName("roomId") val roomId: Long?,
    @SerializedName("roomName") val roomName: String?,
    @SerializedName("longitude") val longitude: Double?,
    @SerializedName("latitude") val latitude: Double?,
    @SerializedName("address") val address: String?
) {
    fun toDomain(): Lock = Lock(
        lockId = lockId ?: 0L,
        lockName = lockName.orEmpty(),
        lockNfcId = lockNfcId.orEmpty(),
        lockType = when (lockType) {
            0 -> LockType.NFC_LOCK
            1 -> LockType.SMART_LOCK
            else -> LockType.UNKNOWN
        },
        status = LockStatus.from(lockStatus),
        batteryLevel = batteryLevel,
        lastHeartbeat = lastHeartbeat,
        roomId = roomId,
        roomName = roomName,
        latitude = latitude,
        longitude = longitude,
        address = address
    )
}
